﻿using Box.Transient.FreeSql.Repository;
using FreeSql;
using ManaSky.Common.Infos;
using ManaSky.DBCore.Entity;
using ManaSky.SSO.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManaSky.Repository.Bases
{
    /// <summary>
    /// 共用仓储
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ShareRepository<T> : FoundRepository<T> where T : BaseEntity, new()
    {
        protected readonly IAuth _auth;
        public ShareRepository(IFreeSql fsql, UnitOfWorkManager unitOfWork, IAuth auth) : base(fsql, unitOfWork)
        {
            this._auth = auth;
            this.UserInfo = GetUserInfo();
        }

        public CurrentUserInfo GetUserInfo()
        {
            var currentUser = new CurrentUserInfo();
            var user = this._auth.GetCurrentUser();
            if (user != null) {
                currentUser.UserID = user.UserID;
                currentUser.UserName = user.UserName;
            }
            return currentUser;
        }
    }
}